﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TracNghiemTinHocDaiCuong.BIZ;
using TracNghiemTinHocDaiCuong.Common;
using TracNghiemTinHocDaiCuong.ThucThe;

namespace TracNghiemTinHocDaiCuong
{
    public partial class SuaCauHoi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CauHoi cauHoiMoi = TimCauHoi();
                txtNoiDung.Text = cauHoiMoi.NoiDung;
                txtDapAnA.Text = cauHoiMoi.DapAnA;
                txtDapAnB.Text = cauHoiMoi.DapAnB;
                txtDapAnC.Text = cauHoiMoi.DapAnC;
                txtDapAnD.Text = cauHoiMoi.DapAnD;
                //ddlChuDe;
                //ddlDoKho
                //ddlDapAn
                ddlChuDe.DataSource = ChuDeBIZ.LayDanhSach();
                ddlChuDe.DataBind();
            }
        }

        private CauHoi TimCauHoi()
        {

            int id = Methods.ConvertNumber(Request.QueryString["ID"]);
            CauHoi cauHoiMoi = CauHoiBIZ.TimKiemTheoId(id);
            return cauHoiMoi;
        }

        protected void btnThem_Click(object sender, EventArgs e)
        {
            CauHoi cauHoi = TimCauHoi();
            CauHoi cauHoiMoi = new CauHoi();
            cauHoiMoi.MaCH = cauHoi.MaCH;
            cauHoiMoi.NoiDung = txtNoiDung.Text;
            cauHoiMoi.DapAnA = txtDapAnA.Text;
            cauHoiMoi.DapAnB = txtDapAnB.Text;
            cauHoiMoi.DapAnC = txtDapAnC.Text;
            cauHoiMoi.DapAnD = txtDapAnD.Text;
            cauHoiMoi.MaCD = Methods.ConvertNumber(ddlChuDe.SelectedValue);
            cauHoiMoi.DoKho = ddlDoKho.SelectedItem.ToString();
            cauHoiMoi.DapAn = ddlDapAn.SelectedItem.ToString();
            CauHoiBIZ.Sua(cauHoiMoi);
            lblThongBao.Text = "Bạn đã sửa câu hỏi thành công";
        }

        protected void btnXoaTuKhoa_Click(object sender, EventArgs e)
        {
            txtNoiDung.Text = "";
            txtDapAnA.Text = "";
            txtDapAnB.Text = "";
            txtDapAnC.Text = "";
            txtDapAnD.Text = "";
        }

        protected void btnQuayLai_Click(object sender, EventArgs e)
        {
            Response.Redirect("QuanLyCauHoi.aspx");
        }
    }
}